<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<div>
	<table id="user-list-dg"></table>
</div>

<script type="text/javascript">
//定义角色列表插件，立即执行方法，只执行一次，所以不需要方法名！！
(function(){
	//初始化插件
	$('#user-list-dg').datagrid({    
	    url:'/user/list',    
	    columns:[[ 
	    	{field:'id',title:'id',hidden:true},    
	        {field:'loginName',title:'登录名称'}, 
	        {field:'phone',title:'手机号码'},    
	        {field:'name',title:'真实名称'}, 
	        {field:'identity',title:'身份证'},    
	        {field:'status',title:'是否启用',width:100,
	        	formatter: function(value,row,index){
					if (value==1){
						var lbtn = '<a id="user-list-status-lbtn" href="#" class="easyui-linkbutton" onclick="javascript:user.edit('+row.id+',2)">禁用</a>';
						return "<font color='green'>启用</font> | " + lbtn;
					} else {
						var lbtn = '<a id="user-list-status-lbtn" href="#" class="easyui-linkbutton" onclick="javascript:user.edit('+row.id+',1)">启用</a>';
						return "<font color='red'>禁用</font> | " + lbtn;
					}
				}
	        },  
	        {field:'creator',title:'创建者'},    
	        {field:'createTime',title:'创建时间',
	        	formatter: function(value,row,index){
					return new Date(value).format("yyyy-MM-dd hh:mm:ss.S");
				}	
	        },    
	        {field:'updateTime',title:'修改时间',
	        	formatter: function(value,row,index){
					return new Date(value).format("yyyy-MM-dd hh:mm:ss.S");
				}	
	        }
	    ]],
	    toolbar: [{
			iconCls: 'icon-add',
			text:'添 加',
			handler: function(){user.openAddWindow();}
		}],
	    pagination:true,
	    pageSize:10,
	    pageList:[10,20,30],
	    rownumbers:true,
	    singleSelect:true
	});
}());

var user = {};

user.openAddWindow=function(){
	//创建一个添加窗口
	$('<div id="user-list-add-dialog"></div>').dialog({    
	    title: '添加角色',    
	    width: 400,    
	    height: 300,    
	    closable:false,    
	    href: '/user/add/',    
	    modal: true,
	    buttons:[{
			text:'添加',
			handler:function(){
				user.add();
			}
		},{
			text:'关闭',
			handler:function(){
				console.info("...user..");
				$('#user-list-add-dialog').dialog('destroy');
			}
		}]
	});  
}

//修改
user.edit=function(id,status){
	console.info(id);
	$.ajax({
	   type: "post",
	   async:false,
	   url: "/user/edit",
	   data:{'id':id,'status':status},
	   success: function(msg){
	     if(msg.code == 200){
	    	//重新加载当前页
	    	$('#user-list-dg').datagrid('reload');
	     }
	   }
	});
}

</script>